package com.oracle.sbdb.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.oracle.sbdb.model.Engineer;

public class EngineerDao {
	public Engineer selectbyId(int engineerId){
		SqlSession session = SessionFactory.getSession();
		Engineer res = session.selectOne("com.oracle.mybatis.EngineerMapper.selectEngineer", engineerId);
		session.commit();
		session.close();
		return res;
	}
	
	public Engineer selectbyEMail(String email){
		SqlSession session = SessionFactory.getSession();
		Engineer res = session.selectOne("com.oracle.mybatis.EngineerMapper.selectEngineerbyEMail", email);
		session.commit();
		session.close();
		return res;
	}
	
	public Engineer selectbyGId(String gid){
		SqlSession session = SessionFactory.getSession();
		Engineer res = session.selectOne("com.oracle.mybatis.EngineerMapper.selectEngineerbyGID", gid);
		session.commit();
		session.close();
		return res;
	}
	
	public List<Engineer> selectEngineerbyDepartmentId(int departmentId){
		SqlSession session = SessionFactory.getSession();
		List<Engineer> res = session.selectList("com.oracle.mybatis.EngineerMapper.selectEngineerbyDepartment", departmentId);
		session.commit();
		session.close();
		return res;
	}
	
	public int selectCount() {
		SqlSession session = SessionFactory.getSession();
		int res = session.selectOne("com.oracle.mybatis.EngineerMapper.selectEngineerCount");
		session.commit();
		session.close();
		return res;
	}
	
	public void insert(Engineer Engineer) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.EngineerMapper.insertEngineer", Engineer);
		session.commit();
		session.close();
	}
	
	public void update(Engineer Engineer) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.EngineerMapper.updateEngineer", Engineer);
		session.commit();
		session.close();
	}
	
	public void delete(int engineerId) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.EngineerMapper.deleteEngineer", engineerId);
		session.commit();
		session.close();
	}
}
